/*
 * NewJFrame.java
 *
 * Created on 2008年3月23日, 下午5:27
 */

package GUI;

import javax.swing.*;
import javax.swing.plaf.FontUIResource;
import java.awt.Font;
import Global.*;
import Manager.Manager;
import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.swing.filechooser.*;
/**
 *
 * @author  littlechild
 */
public class MainFrame extends javax.swing.JFrame {
    Manager manager;
    PanelCavas cavas;
    /** Creates new form NewJFrame */
    public MainFrame() {
        super();
        init();
    }
    public MainFrame(String m) {
        super(m);
        init();
    }
    void init() {
       GlobalOutLook.setFontAll(new FontUIResource("宋体",Font.PLAIN,12));
       GlobalOutLook.setSystemLookAndFeel();
       initComponents();
       this.setSize(800,600);
       this.setLocationRelativeTo(null);
       this.cavas=new PanelCavas(null);
       //this.cavas.setPreferredSize(new Dimension(1024,768));
       this.jScrollPane1.setViewportView(this.cavas);
       this.filechooser.setCurrentDirectory(new File(System.getProperty("user.dir")));
    }
    public void setManager(Manager m) {
        this.manager=m;
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        winMenu = new javax.swing.JMenu();
        newWindow = new javax.swing.JMenuItem();
        cascadeWindow = new javax.swing.JMenuItem();
        tileWindow = new javax.swing.JMenuItem();
        filechooser = new javax.swing.JFileChooser();
        recentFileMenu = new javax.swing.JMenu();
        mainPanel = new javax.swing.JPanel();
        jToolBar1 = new javax.swing.JToolBar();
        openBt = new javax.swing.JButton();
        backBt = new javax.swing.JButton();
        forBt = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        openMenuItem = new javax.swing.JMenuItem();
        closeMenuItem = new javax.swing.JMenuItem();
        saveMenuItem = new javax.swing.JMenuItem();
        saveasMenuItem = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JSeparator();
        jSeparator2 = new javax.swing.JSeparator();
        exitMenuItem = new javax.swing.JMenuItem();
        editMenu = new javax.swing.JMenu();
        backwardkMenuItem = new javax.swing.JMenuItem();
        forwardMenuItem = new javax.swing.JMenuItem();
        dipMenu = new javax.swing.JMenu();
        histogramMenuItem = new javax.swing.JMenuItem();
        jSeparator3 = new javax.swing.JSeparator();
        jMenu1 = new javax.swing.JMenu();
        thresholdMenuItem = new javax.swing.JMenuItem();
        constrastStretchMenuItem = new javax.swing.JMenuItem();
        linearizeMenuItem = new javax.swing.JMenuItem();
        equalizationMenuitem = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        shiftMinusMenuItem = new javax.swing.JMenuItem();
        minusByMenuItem = new javax.swing.JMenuItem();
        addByMenuItem = new javax.swing.JMenuItem();
        jMenu3 = new javax.swing.JMenu();
        horizantalFlipMenuItem = new javax.swing.JMenuItem();
        verticalFlipMenuItem = new javax.swing.JMenuItem();
        affineTransMenuItem = new javax.swing.JMenuItem();
        perspectiveMenuItem = new javax.swing.JMenuItem();
        jMenu4 = new javax.swing.JMenu();
        averageMenuItem = new javax.swing.JMenuItem();
        gaussMenuItem = new javax.swing.JMenuItem();
        jSeparator4 = new javax.swing.JSeparator();
        robertsMenuItem = new javax.swing.JMenuItem();
        prewittMenuItem = new javax.swing.JMenuItem();
        sobelMenuItem = new javax.swing.JMenuItem();
        iSobelMenuItem = new javax.swing.JMenuItem();
        laplacianMenuItem = new javax.swing.JMenuItem();
        jSeparator5 = new javax.swing.JSeparator();
        susanMenuItem = new javax.swing.JMenuItem();
        cannyMenuItem = new javax.swing.JMenuItem();
        jMenu5 = new javax.swing.JMenu();
        dilationMenuIte = new javax.swing.JMenuItem();
        erosionMenuItem = new javax.swing.JMenuItem();
        openingMenuItem = new javax.swing.JMenuItem();
        closingMenuItem = new javax.swing.JMenuItem();
        jSeparator6 = new javax.swing.JSeparator();
        boundaryMenuIte = new javax.swing.JMenuItem();
        skeletonMenuItem = new javax.swing.JMenuItem();
        jMenu6 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenu7 = new javax.swing.JMenu();
        ItemWaveCompression = new javax.swing.JMenuItem();
        ItemWaveWatermark = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        aboutMenuItem = new javax.swing.JMenuItem();

        winMenu.setText("窗口");

        newWindow.setText("新建窗口");
        newWindow.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newWindowActionPerformed(evt);
            }
        });
        winMenu.add(newWindow);

        cascadeWindow.setText("层叠窗口");
        winMenu.add(cascadeWindow);

        tileWindow.setText("平铺窗口");
        winMenu.add(tileWindow);

        recentFileMenu.setText("最近的文档");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jToolBar1.setRollover(true);

        openBt.setText("打开");
        openBt.setFocusable(false);
        openBt.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        openBt.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        openBt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openBtActionPerformed(evt);
            }
        });
        jToolBar1.add(openBt);

        backBt.setText("后退");
        backBt.setFocusable(false);
        backBt.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        backBt.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        backBt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                backBtActionPerformed(evt);
            }
        });
        jToolBar1.add(backBt);

        forBt.setText("前进");
        forBt.setFocusable(false);
        forBt.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        forBt.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        forBt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                forBtActionPerformed(evt);
            }
        });
        jToolBar1.add(forBt);

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 422, Short.MAX_VALUE)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 412, Short.MAX_VALUE)))
                .addContainerGap())
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 232, Short.MAX_VALUE)
                .addGap(22, 22, 22))
        );

        fileMenu.setText("文件");

        openMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK));
        openMenuItem.setText("打开");
        openMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(openMenuItem);

        closeMenuItem.setText("关闭");
        closeMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                closeMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(closeMenuItem);

        saveMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        saveMenuItem.setText("保存");
        saveMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(saveMenuItem);

        saveasMenuItem.setText("另存为");
        saveasMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveasMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(saveasMenuItem);
        fileMenu.add(jSeparator1);
        fileMenu.add(jSeparator2);

        exitMenuItem.setText("退出");
        exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        editMenu.setText("编辑");

        backwardkMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Z, java.awt.event.InputEvent.CTRL_MASK));
        backwardkMenuItem.setText("撤销");
        backwardkMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                backwardkMenuItemActionPerformed(evt);
            }
        });
        editMenu.add(backwardkMenuItem);

        forwardMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Y, java.awt.event.InputEvent.CTRL_MASK));
        forwardMenuItem.setText("前进");
        forwardMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                forwardMenuItemActionPerformed(evt);
            }
        });
        editMenu.add(forwardMenuItem);

        menuBar.add(editMenu);

        dipMenu.setText("图像处理");

        histogramMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_H, java.awt.event.InputEvent.ALT_MASK));
        histogramMenuItem.setText("直方图");
        histogramMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                histogramMenuItemActionPerformed(evt);
            }
        });
        dipMenu.add(histogramMenuItem);
        dipMenu.add(jSeparator3);

        jMenu1.setText("点运算");

        thresholdMenuItem.setText("阈值化");
        thresholdMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                thresholdMenuItemActionPerformed(evt);
            }
        });
        jMenu1.add(thresholdMenuItem);

        constrastStretchMenuItem.setText("反相");
        constrastStretchMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                constrastStretchMenuItemActionPerformed(evt);
            }
        });
        jMenu1.add(constrastStretchMenuItem);

        linearizeMenuItem.setText("线性化");
        linearizeMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                linearizeMenuItemActionPerformed(evt);
            }
        });
        jMenu1.add(linearizeMenuItem);

        equalizationMenuitem.setText("直方图均衡化");
        equalizationMenuitem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                equalizationMenuitemActionPerformed(evt);
            }
        });
        jMenu1.add(equalizationMenuitem);

        dipMenu.add(jMenu1);

        jMenu2.setText("代数运算");

        shiftMinusMenuItem.setText("平移相减");
        shiftMinusMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                shiftMinusMenuItemActionPerformed(evt);
            }
        });
        jMenu2.add(shiftMinusMenuItem);

        minusByMenuItem.setText("与...相减");
        minusByMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                minusByMenuItemActionPerformed(evt);
            }
        });
        jMenu2.add(minusByMenuItem);

        addByMenuItem.setText("与...相加");
        addByMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addByMenuItemActionPerformed(evt);
            }
        });
        jMenu2.add(addByMenuItem);

        dipMenu.add(jMenu2);

        jMenu3.setText("几何运算");

        horizantalFlipMenuItem.setText("水平翻转");
        horizantalFlipMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                horizantalFlipMenuItemActionPerformed(evt);
            }
        });
        jMenu3.add(horizantalFlipMenuItem);

        verticalFlipMenuItem.setText("垂直翻转");
        verticalFlipMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                verticalFlipMenuItemActionPerformed(evt);
            }
        });
        jMenu3.add(verticalFlipMenuItem);

        affineTransMenuItem.setText("仿射变换");
        affineTransMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                affineTransMenuItemActionPerformed(evt);
            }
        });
        jMenu3.add(affineTransMenuItem);

        perspectiveMenuItem.setText("透视变换");
        perspectiveMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                perspectiveMenuItemActionPerformed(evt);
            }
        });
        jMenu3.add(perspectiveMenuItem);

        dipMenu.add(jMenu3);

        jMenu4.setText("领域运算");

        averageMenuItem.setText("领域平均");
        averageMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                averageMenuItemActionPerformed(evt);
            }
        });
        jMenu4.add(averageMenuItem);

        gaussMenuItem.setText("高斯滤波");
        gaussMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                gaussMenuItemActionPerformed(evt);
            }
        });
        jMenu4.add(gaussMenuItem);
        jMenu4.add(jSeparator4);

        robertsMenuItem.setText("Roberts算子");
        robertsMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                robertsMenuItemActionPerformed(evt);
            }
        });
        jMenu4.add(robertsMenuItem);

        prewittMenuItem.setText("Prewitt算子");
        prewittMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                prewittMenuItemActionPerformed(evt);
            }
        });
        jMenu4.add(prewittMenuItem);

        sobelMenuItem.setText("Sobel算子");
        sobelMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sobelMenuItemActionPerformed(evt);
            }
        });
        jMenu4.add(sobelMenuItem);

        iSobelMenuItem.setText("I。Sobel算子");
        iSobelMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                iSobelMenuItemActionPerformed(evt);
            }
        });
        jMenu4.add(iSobelMenuItem);

        laplacianMenuItem.setText("Laplacian算子");
        laplacianMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                laplacianMenuItemActionPerformed(evt);
            }
        });
        jMenu4.add(laplacianMenuItem);
        jMenu4.add(jSeparator5);

        susanMenuItem.setText("Susan检测");
        susanMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                susanMenuItemActionPerformed(evt);
            }
        });
        jMenu4.add(susanMenuItem);

        cannyMenuItem.setText("Canny检测");
        cannyMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cannyMenuItemActionPerformed(evt);
            }
        });
        jMenu4.add(cannyMenuItem);

        dipMenu.add(jMenu4);

        jMenu5.setText("形态学运算");

        dilationMenuIte.setText("膨胀");
        dilationMenuIte.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dilationMenuIteActionPerformed(evt);
            }
        });
        jMenu5.add(dilationMenuIte);

        erosionMenuItem.setText("腐蚀");
        erosionMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                erosionMenuItemActionPerformed(evt);
            }
        });
        jMenu5.add(erosionMenuItem);

        openingMenuItem.setText("开运算");
        openingMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openingMenuItemActionPerformed(evt);
            }
        });
        jMenu5.add(openingMenuItem);

        closingMenuItem.setText("闭运算");
        closingMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                closingMenuItemActionPerformed(evt);
            }
        });
        jMenu5.add(closingMenuItem);
        jMenu5.add(jSeparator6);

        boundaryMenuIte.setText("边界");
        boundaryMenuIte.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                boundaryMenuIteActionPerformed(evt);
            }
        });
        jMenu5.add(boundaryMenuIte);

        skeletonMenuItem.setText("骨架");
        skeletonMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                skeletonMenuItemActionPerformed(evt);
            }
        });
        jMenu5.add(skeletonMenuItem);

        jMenu6.setText("细化");

        jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem1.setText("单步");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu6.add(jMenuItem1);

        jMenuItem2.setText("连续");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu6.add(jMenuItem2);

        jMenu5.add(jMenu6);

        dipMenu.add(jMenu5);

        menuBar.add(dipMenu);

        jMenu7.setText("小波应用");

        ItemWaveCompression.setText("小波压缩");
        ItemWaveCompression.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ItemWaveCompressionActionPerformed(evt);
            }
        });
        jMenu7.add(ItemWaveCompression);

        ItemWaveWatermark.setText("小波水印");
        ItemWaveWatermark.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ItemWaveWatermarkActionPerformed(evt);
            }
        });
        jMenu7.add(ItemWaveWatermark);

        menuBar.add(jMenu7);

        helpMenu.setText("帮助");

        aboutMenuItem.setText("关于");
        aboutMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aboutMenuItemActionPerformed(evt);
            }
        });
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        setJMenuBar(menuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(mainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(mainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void openBtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openBtActionPerformed
        // TODO add your handling code here:
        openMenuItemActionPerformed(evt);
    }//GEN-LAST:event_openBtActionPerformed

    private void openMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openMenuItemActionPerformed
        // TODO add your handling code here:
        //this.filechooser.setCurrentDirectory(new File(System.getProperty("user.dir")));
        this.filechooser.setDialogTitle("打开bmp文件");
        FileNameExtensionFilter filter=new FileNameExtensionFilter("BMP","BMP");
        this.filechooser.setFileFilter(filter);
        int returnValue=this.filechooser.showOpenDialog(this);
        if(returnValue==JFileChooser.APPROVE_OPTION) {
            String paras[]=new String[1];
            paras[0]=this.filechooser.getSelectedFile().getPath();
            BufferedImage image=manager.operate(Global.fileopen,paras);
            this.cavas.setImage(image);
            //this.jScrollPane1.updateUI();
         }   
    }//GEN-LAST:event_openMenuItemActionPerformed

    private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
        // TODO add your handling code here:
        System.exit(0);
    }//GEN-LAST:event_exitMenuItemActionPerformed

    private void closeMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeMenuItemActionPerformed
        // TODO add your handling code here:
        manager.operate(Global.fileclose, null);
        this.cavas.setImage(null);
        this.jScrollPane1.updateUI();
    }//GEN-LAST:event_closeMenuItemActionPerformed

    private void saveMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveMenuItemActionPerformed
        // TODO add your handling code here:
        manager.operate(Global.filesave,null);
    }//GEN-LAST:event_saveMenuItemActionPerformed

    private void saveasMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveasMenuItemActionPerformed
        // TODO add your handling code here:

        this.filechooser.setDialogTitle("保存bmp文件");
        FileNameExtensionFilter filter=new FileNameExtensionFilter("BMP","BMP");
        this.filechooser.setFileFilter(filter);
        int returnValue=this.filechooser.showSaveDialog(this);
        if(returnValue==JFileChooser.APPROVE_OPTION) {
            String paras[]=new String[1];
            paras[0]=this.filechooser.getSelectedFile().getPath();
            manager.operate(Global.filesaveas,paras);
         } 
    }//GEN-LAST:event_saveasMenuItemActionPerformed

    private void forBtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_forBtActionPerformed
        // TODO add your handling code here:
        forwardMenuItemActionPerformed(evt);
}//GEN-LAST:event_forBtActionPerformed

    private void backwardkMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backwardkMenuItemActionPerformed
        // TODO add your handling code here:
        BufferedImage image=manager.operate(Global.editBack, null);
        if(image!=null)
            this.cavas.setImage(image);
        else
            System.out.println("can not go backward any more");
    }//GEN-LAST:event_backwardkMenuItemActionPerformed

    private void forwardMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_forwardMenuItemActionPerformed
        // TODO add your handling code here:
        BufferedImage image=manager.operate(Global.editFor, null);
        if(image!=null)
            this.cavas.setImage(image);
        else
            System.out.println("can not go forward any more");
    }//GEN-LAST:event_forwardMenuItemActionPerformed

    private void backBtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backBtActionPerformed
        // TODO add your handling code here:
        backwardkMenuItemActionPerformed(null);
    }//GEN-LAST:event_backBtActionPerformed

    private void histogramMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_histogramMenuItemActionPerformed
        // TODO add your handling code here:
        JDialog jd=new RelatedDialog(this,"直方图",manager,cavas);
        PanelHistogram ph=new PanelHistogram(manager);
        jd.add(ph);
        jd.pack();
        jd.setLocationRelativeTo(this);
        jd.setVisible(true);
    }//GEN-LAST:event_histogramMenuItemActionPerformed

    private void equalizationMenuitemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_equalizationMenuitemActionPerformed
        // TODO add your handling code here:
        //send message to the manager about this action
        BufferedImage image=manager.operate(Global.opEqualization,null);
        //render the image
        this.cavas.setImage(image);
    }//GEN-LAST:event_equalizationMenuitemActionPerformed

    private void thresholdMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_thresholdMenuItemActionPerformed
        // TODO add your handling code here:
        JDialog jd=new RelatedDialog(this,"阈值化",manager,cavas);
        PanelThreshold pt=new PanelThreshold(manager,this.cavas);
        jd.add(pt);
        jd.pack();
        jd.setLocationRelativeTo(this);
        jd.setVisible(true);
    }//GEN-LAST:event_thresholdMenuItemActionPerformed

    private void constrastStretchMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_constrastStretchMenuItemActionPerformed
        // TODO add your handling code here:
        BufferedImage image=manager.operate(Global.opContrastStretch, null);
        this.cavas.setImage(image);
    }//GEN-LAST:event_constrastStretchMenuItemActionPerformed

    private void linearizeMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_linearizeMenuItemActionPerformed
        // TODO add your handling code here:
        JDialog jd=new RelatedDialog(this,"线性化",manager,cavas);
        JPanel jp=new PanelLinearization(manager,cavas);
        jd.add(jp);
        jd.pack();
        jd.setLocationRelativeTo(this);
        jd.setVisible(true);
    }//GEN-LAST:event_linearizeMenuItemActionPerformed

    private void shiftMinusMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_shiftMinusMenuItemActionPerformed
        // TODO add your handling code here:
        JDialog jd=new RelatedDialog(this,"平移相减",manager,cavas);
        JPanel jp=new PanelShiftMinus(manager,cavas);
        jd.add(jp);
        jd.pack();
        jd.setLocationRelativeTo(this);
        jd.setVisible(true);
    }//GEN-LAST:event_shiftMinusMenuItemActionPerformed

    private void minusByMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_minusByMenuItemActionPerformed
        // TODO add your handling code here:
        //this.filechooser.setCurrentDirectory(new File(System.getProperty("user.dir")));
        this.filechooser.setDialogTitle("打开bmp文件");
        FileNameExtensionFilter filter=new FileNameExtensionFilter("BMP","BMP");
        this.filechooser.setFileFilter(filter);
        int returnValue=this.filechooser.showOpenDialog(this);
        if(returnValue==JFileChooser.APPROVE_OPTION) {
            String paras[]=new String[1];
            paras[0]=this.filechooser.getSelectedFile().getPath();
            BufferedImage image=manager.operate(Global.opMinuswith,paras);
            this.cavas.setImage(image);
            this.jScrollPane1.updateUI();
         }   
    }//GEN-LAST:event_minusByMenuItemActionPerformed

    private void addByMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addByMenuItemActionPerformed
        // TODO add your handling code here:
        //this.filechooser.setCurrentDirectory(new File(System.getProperty("user.dir")));
        this.filechooser.setDialogTitle("打开bmp文件");
        FileNameExtensionFilter filter=new FileNameExtensionFilter("BMP","BMP");
        this.filechooser.setFileFilter(filter);
        int returnValue=this.filechooser.showOpenDialog(this);
        if(returnValue==JFileChooser.APPROVE_OPTION) {
            String paras[]=new String[1];
            paras[0]=this.filechooser.getSelectedFile().getPath();
            BufferedImage image=manager.operate(Global.opAddwith,paras);
            this.cavas.setImage(image);
            this.jScrollPane1.updateUI();
         }   
    }//GEN-LAST:event_addByMenuItemActionPerformed

    private void horizantalFlipMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_horizantalFlipMenuItemActionPerformed
        // TODO add your handling code here:
        this.cavas.setImage(manager.operate(Global.opFliplr, null));
    }//GEN-LAST:event_horizantalFlipMenuItemActionPerformed

    private void verticalFlipMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_verticalFlipMenuItemActionPerformed
        // TODO add your handling code here:
        this.cavas.setImage(manager.operate(Global.opFlipud, null));
    }//GEN-LAST:event_verticalFlipMenuItemActionPerformed

    private void affineTransMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_affineTransMenuItemActionPerformed
        // TODO add your handling code here:
        JDialog jd=new RelatedDialog(this,"仿射变换",manager,cavas);
        JPanel jp=new PanelAffine(manager,cavas);
        jd.add(jp);
        jd.pack();
        jd.setLocationRelativeTo(this);
        jd.setVisible(true);
    }//GEN-LAST:event_affineTransMenuItemActionPerformed

    private void averageMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_averageMenuItemActionPerformed
        // TODO add your handling code here:
        this.cavas.setImage(manager.operate(Global.opNeighbourAverage, null));
    }//GEN-LAST:event_averageMenuItemActionPerformed

    private void gaussMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_gaussMenuItemActionPerformed
        // TODO add your handling code here:
        this.cavas.setImage(manager.operate(Global.opGaussFiltering, null));
    }//GEN-LAST:event_gaussMenuItemActionPerformed

    private void robertsMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_robertsMenuItemActionPerformed
        // TODO add your handling code here:
        this.cavas.setImage(manager.operate(Global.opRoberts, null));
    }//GEN-LAST:event_robertsMenuItemActionPerformed

    private void prewittMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_prewittMenuItemActionPerformed
        // TODO add your handling code here:
        this.cavas.setImage(manager.operate(Global.opPrewitt, null));
    }//GEN-LAST:event_prewittMenuItemActionPerformed

    private void sobelMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sobelMenuItemActionPerformed
        // TODO add your handling code here:
        this.cavas.setImage(manager.operate(Global.opSobel, null));
    }//GEN-LAST:event_sobelMenuItemActionPerformed

    private void iSobelMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_iSobelMenuItemActionPerformed
        // TODO add your handling code here:
        this.cavas.setImage(manager.operate(Global.opISobel, null));
    }//GEN-LAST:event_iSobelMenuItemActionPerformed

    private void laplacianMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_laplacianMenuItemActionPerformed
        // TODO add your handling code here:
        JDialog jd=new RelatedDialog(this,"Laplacian 算子",manager,cavas);
        JPanel jp=new PanelLaplacian(manager,cavas);
        jd.add(jp);
        jd.pack();
        jd.setLocationRelativeTo(this);
        jd.setVisible(true);
    }//GEN-LAST:event_laplacianMenuItemActionPerformed

    private void cannyMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cannyMenuItemActionPerformed
        // TODO add your handling code here:
        JDialog jd=new RelatedDialog(this,"Canny 边缘检测",manager,cavas);
        JPanel jp=new PanelCanny(manager,cavas);
        jd.add(jp);
        jd.pack();
        jd.setLocationRelativeTo(this);
        jd.setVisible(true);
    }//GEN-LAST:event_cannyMenuItemActionPerformed

    private void susanMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_susanMenuItemActionPerformed
        // TODO add your handling code here:
        JDialog jd=new RelatedDialog(this,"Susan 边缘检测",manager,cavas);
        JPanel jp=new PanelSusan(manager,cavas);
        jd.add(jp);
        jd.pack();
        jd.setLocationRelativeTo(this);
        jd.setVisible(true);
    }//GEN-LAST:event_susanMenuItemActionPerformed

    private void erosionMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_erosionMenuItemActionPerformed
        // TODO add your handling code here:
        this.cavas.setImage(manager.operate(Global.opErosion, null));
    }//GEN-LAST:event_erosionMenuItemActionPerformed

    private void dilationMenuIteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dilationMenuIteActionPerformed
        // TODO add your handling code here:
        this.cavas.setImage(manager.operate(Global.opDilation, null));
    }//GEN-LAST:event_dilationMenuIteActionPerformed

    private void openingMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openingMenuItemActionPerformed
        // TODO add your handling code here:
        this.cavas.setImage(manager.operate(Global.opOpening, null));
    }//GEN-LAST:event_openingMenuItemActionPerformed

    private void closingMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closingMenuItemActionPerformed
        // TODO add your handling code here:
        this.cavas.setImage(manager.operate(Global.opClosing, null));
    }//GEN-LAST:event_closingMenuItemActionPerformed

    private void boundaryMenuIteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_boundaryMenuIteActionPerformed
        // TODO add your handling code here:
        this.cavas.setImage(manager.operate(Global.opBoundary, null));
    }//GEN-LAST:event_boundaryMenuIteActionPerformed

    private void skeletonMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_skeletonMenuItemActionPerformed
        // TODO add your handling code here:
        this.cavas.setImage(manager.operate(Global.opSkeleton, null));
    }//GEN-LAST:event_skeletonMenuItemActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        // TODO add your handling code here:
        this.cavas.setImage(
                manager.operate(Global.opThinning, new String[]{String.valueOf(Global.thinningSingle)}));
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        // TODO add your handling code here:
       this.cavas.setImage(
                manager.operate(Global.opThinning, new String[]{String.valueOf(Global.thinningContinuous)}));
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void perspectiveMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_perspectiveMenuItemActionPerformed
        // TODO add your handling code here:
        JDialog jd=new RelatedDialog(this,"透射变化",manager,cavas);
        JPanel jp=new PanelPersp(manager,cavas);
        jd.add(jp);
        jd.pack();
        jd.setLocationRelativeTo(this);
        jd.setVisible(true);
    }//GEN-LAST:event_perspectiveMenuItemActionPerformed

    private void newWindowActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newWindowActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_newWindowActionPerformed

    private void aboutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aboutMenuItemActionPerformed
        // TODO add your handling code here:
        JOptionPane.showMessageDialog(this, "Dip课程实验 v2008\n作者： 张旋 2005013104", "关于Dip课程实验", JOptionPane.INFORMATION_MESSAGE);
    }//GEN-LAST:event_aboutMenuItemActionPerformed

    private void ItemWaveCompressionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ItemWaveCompressionActionPerformed
        // TODO add your handling code here:
        JDialog jd=new RelatedDialog(this,"小波压缩",manager,cavas);
        JPanel jp=new PanelWaveletCompress(manager);
        jd.add(jp);
        jd.pack();
        jd.setLocationRelativeTo(this);
        jd.setVisible(true);
    }//GEN-LAST:event_ItemWaveCompressionActionPerformed

    private void ItemWaveWatermarkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ItemWaveWatermarkActionPerformed
        // TODO add your handling code here:
        JDialog jd=new RelatedDialog(this,"小波水印",manager,cavas);
        JPanel jp=new PanelWaveletWatermark(manager);
        jd.add(jp);
        jd.pack();
        jd.setLocationRelativeTo(this);
        jd.setVisible(true);
    }//GEN-LAST:event_ItemWaveWatermarkActionPerformed
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MainFrame().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem ItemWaveCompression;
    private javax.swing.JMenuItem ItemWaveWatermark;
    private javax.swing.JMenuItem aboutMenuItem;
    private javax.swing.JMenuItem addByMenuItem;
    private javax.swing.JMenuItem affineTransMenuItem;
    private javax.swing.JMenuItem averageMenuItem;
    private javax.swing.JButton backBt;
    private javax.swing.JMenuItem backwardkMenuItem;
    private javax.swing.JMenuItem boundaryMenuIte;
    private javax.swing.JMenuItem cannyMenuItem;
    private javax.swing.JMenuItem cascadeWindow;
    private javax.swing.JMenuItem closeMenuItem;
    private javax.swing.JMenuItem closingMenuItem;
    private javax.swing.JMenuItem constrastStretchMenuItem;
    private javax.swing.JMenuItem dilationMenuIte;
    private javax.swing.JMenu dipMenu;
    private javax.swing.JMenu editMenu;
    private javax.swing.JMenuItem equalizationMenuitem;
    private javax.swing.JMenuItem erosionMenuItem;
    private javax.swing.JMenuItem exitMenuItem;
    private javax.swing.JFileChooser filechooser;
    private javax.swing.JButton forBt;
    private javax.swing.JMenuItem forwardMenuItem;
    private javax.swing.JMenuItem gaussMenuItem;
    private javax.swing.JMenuItem histogramMenuItem;
    private javax.swing.JMenuItem horizantalFlipMenuItem;
    private javax.swing.JMenuItem iSobelMenuItem;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenu jMenu4;
    private javax.swing.JMenu jMenu5;
    private javax.swing.JMenu jMenu6;
    private javax.swing.JMenu jMenu7;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JSeparator jSeparator5;
    private javax.swing.JSeparator jSeparator6;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JMenuItem laplacianMenuItem;
    private javax.swing.JMenuItem linearizeMenuItem;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JMenuItem minusByMenuItem;
    private javax.swing.JMenuItem newWindow;
    private javax.swing.JButton openBt;
    private javax.swing.JMenuItem openMenuItem;
    private javax.swing.JMenuItem openingMenuItem;
    private javax.swing.JMenuItem perspectiveMenuItem;
    private javax.swing.JMenuItem prewittMenuItem;
    private javax.swing.JMenu recentFileMenu;
    private javax.swing.JMenuItem robertsMenuItem;
    private javax.swing.JMenuItem saveMenuItem;
    private javax.swing.JMenuItem saveasMenuItem;
    private javax.swing.JMenuItem shiftMinusMenuItem;
    private javax.swing.JMenuItem skeletonMenuItem;
    private javax.swing.JMenuItem sobelMenuItem;
    private javax.swing.JMenuItem susanMenuItem;
    private javax.swing.JMenuItem thresholdMenuItem;
    private javax.swing.JMenuItem tileWindow;
    private javax.swing.JMenuItem verticalFlipMenuItem;
    private javax.swing.JMenu winMenu;
    // End of variables declaration//GEN-END:variables

}
class GlobalOutLook {
    static void setFontAll(FontUIResource font) {
        UIManager.put("Button.font", font);
        UIManager.put("ToggleButton.font", font);
        UIManager.put("RadioButton.font", font);
        UIManager.put("CheckBox.font", font);
        UIManager.put("ColorChooser.font", font);
        UIManager.put("ComboBox.font", font);
        UIManager.put("Label.font",font);
        UIManager.put("List.font", font);
        UIManager.put("MenuBar.font", font);
        UIManager.put("MenuItem.font", font);
        UIManager.put("RadioButtonMenuItem.font", font);
        UIManager.put("CheckBoxMenuItem.font", font);
        UIManager.put("Menu.font", font);
        UIManager.put("PopupMenu.font", font);
        UIManager.put("OptionPane.font", font);
        UIManager.put("Panel.font", font);
        UIManager.put("ProgressBar.font", font);
        UIManager.put("ScrollPane.font", font);
        UIManager.put("Viewport.font", font);
        UIManager.put("TabbedPane.font", font);
        UIManager.put("Table.font", font);
        UIManager.put("TableHeader.font", font);
        UIManager.put("TextField.font", font);
        UIManager.put("PasswordField.font", font);
        UIManager.put("TextArea.font", font);
        UIManager.put("TextPane.font",font);
        UIManager.put("EditorPane.font",font);
        UIManager.put("TitledBorder.font", font);
        UIManager.put("ToolBar.font", font);
        UIManager.put("ToolTip.font",font);
        UIManager.put("Tree.font", font);
    }
    static void setSystemLookAndFeel() {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (UnsupportedLookAndFeelException ex) {
            ex.printStackTrace();
        } catch (InstantiationException ex) {
            ex.printStackTrace();
        } catch (IllegalAccessException ex) {
            ex.printStackTrace();
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        }
    }
}